<template>
    <div>
        <el-row>
            <el-col :span="6">
                <el-input v-model="searchData"  placeholder="输入姓名搜索"></el-input>
            </el-col>
            <el-col :span="2">
                <el-button type="primary" @click="search">搜索</el-button>
            </el-col>
            <el-button type="success"  @click="addReturnOrder">添加</el-button>
        </el-row>
        <h1 style="text-align: center">退货表</h1>
        <el-table
                :data="tableData"
                border
                stripe
                style="width: 100%">
            <el-table-column
                    fixed
                    prop="re_id"
                    label="编号"
                    width="70">
            </el-table-column>
            <el-table-column
                    prop="buyerName"
                    label="买家姓名"
                    width="120">
            </el-table-column>
            <el-table-column
                    prop="buyerPhone"
                    label="买家电话"
                    width="120">
            </el-table-column>
            <el-table-column
                    prop="returnDate"
                    label="退款日期"
                    width="200">
            </el-table-column>
            <el-table-column
                    prop="returnWay"
                    label="退款方式"
                    width="80">
            </el-table-column>
            <el-table-column
                    prop="returnNote"
                    label="退款说明"
                    width="300">
            </el-table-column>
            <el-table-column
                    prop="returnCount"
                    label="退款数量"
                    width="80">
            </el-table-column>
            <el-table-column
                    prop="returnPrice"
                    label="退款价格"
                    width="120">
            </el-table-column>
            <el-table-column
                    fixed="right"
                    label="操作"
                    width="160">
                <template slot-scope="scope">
<!--                    <el-button @click="edit(scope.row)" type="primary" icon="el-icon-edit" circle size="mini">修改</el-button>-->
                    <el-button @click="deleteReturnOrderById(scope.row)" type="danger" circle icon="el-icon-delete"  size="mini">删除</el-button>
                </template>
            </el-table-column>
        </el-table>
        <el-pagination
                background
                layout="prev, pager, next"
                :page-size="5"
                @current-change="page"
                :total="total">
        </el-pagination>
    </div>
</template>


<script>
    import qs from "qs";
    export default {
        methods: {
            search(){
                var that = this;
                console.log(this.searchData);
                axios.get('http://localhost:8080/ocp/returnOrder/selectReturnOrderByName?buyerName='+this.searchData).then(function (resp) {
                    console.log(resp);
                    console.log(resp.data.row);
                    that.tableData = resp.data.row;
                })
            },
            edit(row) {
                this.$router.push({
                    path: '/updateReturnOrder',
                    query:{
                        id: row.re_id
                    }
                })
                console.log(row);
            },
            addReturnOrder(){
                this.$router.push({
                    path: '/addReturnOrder',
                })
            },
            deleteReturnOrderById(row){
                console.log(row);
                axios.get('http://localhost:8080/ocp/returnOrder/deleteReturnOrderById?re_id='+row.re_id).then(function (resp) {
                    console.log(resp);
                })
                window.location.reload();
            },
            page(currentPage){
                var that = this;
                axios.get('http://localhost:8080/ocp/returnOrder/getAllReturnOrderByPage?current_page='+currentPage).then(function (resp) {
                    console.log(resp);
                    that.tableData = resp.data.rows;
                    that.total=resp.data.total;
                })
            }
        },

        data() {
            return {
                searchData: "",
                total: 20,
                tableData:[],
            }
        },
        created () {
            var that = this;
            axios.get('http://localhost:8080/ocp/returnOrder/getAllReturnOrderByPage').then(function (resp) {
                console.log(resp);
                that.tableData = resp.data.rows;
                that.total=resp.data.total;
            })
        }
    }
</script>
